package com.im.test.core;

import com.alibaba.fastjson.JSONObject;
import com.im.test.bean.LiveRoomMessageBean;
import com.im.test.constant.WebSocketRequestType;
import org.java_websocket.client.WebSocketClient;

import java.net.URI;

public class WebSocketInstance {
    private static MyWebSocketClinet clinet;

    private static String getToken() {
        return "ffRAd0TURqxj3H3h9nY%2BI6xqMScPCOwJeNWnVSWsdgBicisEGWOTEtlpeAzII%2B1gYss6P3Bo9saO8qEV1SSUBu6%2BYD1Pgp6z85hWmjDL0cK6c8FN8RF6uakmUXg0lmYn%2Fe6L54fj32Ws2DQiSKVkQawfAShgSYZ4gyXwPLm3ezvbjqBlKgIGQD7gYrcHfjkVodcg0c3QyAt4MYG3T1uKafV8AemcriP2vh95pMe3bsec%2Bu5lLijrs4xOw%2Fti4CxzZP3LqOfK%2FGcgXSLplBWXjw%3D%3D";
    }

    public static MyWebSocketClinet getInstance(String url, String token) {
        URI uri = URI.create("ws://" + url + "/chatsocket?request=" + token);
        clinet = new MyWebSocketClinet(uri);
        WebSocketMessageListener webSocketMessageListener = new WebSocketMessageListener();
        clinet.setMessageListener(webSocketMessageListener);
        return clinet;
    }

//    public static void main(String[] args) {
//        MyWebSocketClinet instance = WebSocketInstance.getInstance("192.168.2.139:8803", "9J0IuyZyjVjCiVW7Eo9y%2FYLlSjGf7n5C4zsPvdzObpIT%2FAW78XndpM%2BmVcGSJrwWfqK%2FC%2FgBH%2BUGIjkez9fi0zdg6UbMPA%2B6zHj02vgBnQnj4W2ONZZxerh%2BKj3Sac3cjEqRhJMpWFN%2FgFFpEInQAQBOnnS%2FKeZjeRpj66JdN%2B5HVS4XUB74J%2F7cHHYQjPR6m5nhrBnocw3BlegoJGYEzX%2FvTBUcd3DHbp14MlZHfFUF6azPxt5UCv20w5uw76LPVYSiCLhuStUa6eJmR0hAxbQFyCOfqB95Ciok3H2z%2FUHl9bojr%2BotiEVP6fGkQ4wdJYgIQywInVDfWvRshxohRV1YK509vM89skctlN6ic3dgArXPkzqpu9wew6YwdIwreEbiLajzfApbMLxHkObXkQ%3D%3D");
//        instance.tryConnect(false);
//        while (!instance.isOpen()) {
//            try {
//                Thread.sleep(2000L);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
//
//        LiveRoomMessageBean liveRoomMessageBean = new LiveRoomMessageBean();
//        liveRoomMessageBean.setGuardLevel(2);
//        liveRoomMessageBean.setHead(null);
//        liveRoomMessageBean.setInRoomState(0);
//        liveRoomMessageBean.setIsAdmin(0);
//        liveRoomMessageBean.setSuperAdmin(0);
//        liveRoomMessageBean.setVipLevel(5);
//        liveRoomMessageBean.setLevel(100);
//        liveRoomMessageBean.setNickName("小沈");
//        liveRoomMessageBean.setMessage("进入房间");
//        liveRoomMessageBean.setUserId("199");
//        liveRoomMessageBean.setUserType(1);
//
//
//        instance.sendMessage(WebSocketRequestType.RequestAction.ENTER.getValue(), JSONObject.toJSONString(liveRoomMessageBean),true);
//
//        while (true){
//            try {
//                Thread.sleep(10L);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//
//            LiveRoomMessageBean liveRoomMessageBean1 = new LiveRoomMessageBean() {{
//                setGuardLevel(2);
//                setInRoomState(0);
//                setIsAdmin(0);
//                setSuperAdmin(0);
//                setVipLevel(5);
//                setLevel(100);
//                setNickName("你爸爸");
//                setMessage("HELLO");
//                setUserId("199");
//                setUserType(1);
//            }};
//            instance.sendMessage(WebSocketRequestType.RequestAction.MESSAGE.getValue(), JSONObject.toJSONString(
//                    liveRoomMessageBean1
//            ),true);
//        }
//
//    }

}
